package com.crb.oauth2.api.wechat.cp.handler;

import com.crb.oauth2.api.wechat.cp.utils.JsonUtils;
import com.crb.oauth2.api.wechat.cp.builder.TextBuilder;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.WxCpXmlMessage;
import me.chanjar.weixin.cp.bean.WxCpXmlOutMessage;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 自建应用审批状态变化事件处理器.
 *
 * @author Binary Wang(https://github.com/binarywang)
 */
@Component
public class OpenApprovalChangeHandler extends AbstractHandler {

    @Override
    public WxCpXmlOutMessage handle(WxCpXmlMessage wxMessage, Map<String, Object> context, WxCpService cpService,
                                    WxSessionManager sessionManager) {
        String content = "自建应用审批状态变化变更事件，内容：" + JsonUtils.toJson(wxMessage);
        this.logger.info(content);
        //自建应用审批状态变化通知回调
        WxCpXmlMessage.ApprovalInfo approvalInfo = wxMessage.getApprovalInfo();
        approvalInfo.getSpStatus();
        approvalInfo.getTemplateId();
        approvalInfo.getSpName();
        approvalInfo.getApplyTime();
        WxCpXmlMessage.ApprovalInfo.Applier applyer = approvalInfo.getApplier();
        applyer.getUserId();
        applyer.getParty();
        return new TextBuilder().build(content, wxMessage, cpService);
    }

}
